package com.blacktea.cloudconsumerorder.controller;

import com.blacktea.cloudapicommon.beans.CommonResult;
import com.blacktea.cloudapicommon.beans.Payment;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @description:
 * @author: black tea
 * @date: 2021/7/28 14:44
 */
@RestController
@RequestMapping("order")
@RequiredArgsConstructor
@Slf4j
public class OrderController {

    private final RestTemplate restTemplate;

//    public static final String PAYMENT_URL = "http://localhost:8001";
    // 使用eureka上面的注册地址
    public static final String PAYMENT_URL = "http://CLOUD-PROVIDER-PAYMENT-SERVICE";
    public static final String API = PAYMENT_URL + "/payment";

    @PostMapping("consumer/payment/create")
    public CommonResult create(@RequestBody Payment payment){
       return restTemplate.postForObject(API+"/create",payment,CommonResult.class);
    }

    @GetMapping("/consumer/payment/get/{paymentId}")
    public CommonResult create(@PathVariable("paymentId") Long paymentId){
        return restTemplate.getForObject(API+"/"+paymentId,CommonResult.class);
    }

    @PostMapping("/consumer/payment/update")
    public CommonResult update(@RequestBody Payment payment){
        return restTemplate.postForObject(API+"/update",payment,CommonResult.class);
    }

    @GetMapping("/consumer/sleuth/zipkin")
    public CommonResult zipkin(){
        return restTemplate.getForObject(PAYMENT_URL+"/sleuth/zipkin",CommonResult.class);
    }
}
